<!--
 * @Author: coman
 * @LastEditors: coman
 * @Date: 2020-06-15 17:13:47
 * @motto: No pain,No gain
 * @LastEditTime: 2020-06-15 17:29:25
--> 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="">
        <input type="text" id="num1">
        <button id="change" type="button">点击获取</button>
        <br>
        <input type="button" value="提交" id="sub">
    </form>
    <script>
        change.onclick=function(){
        //   生成一个随机四位数
        var ran = Math.random()*9000+1000;
         change.innerHTML=parseInt(ran);

        }
        sub.onclick=function(){
            if(num1.value===change.innerHTML){
                alert("验证码正确")
        }else{
            alert("验证码错误")
        }
        }
        
    </script>
</body>
</html>